package org.budo.support.javax.servlet.filter.request.read.repeatable;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;

/**
 * @author lmw
 */
public class ByteArrayServletInputStream extends ServletInputStream {
    private final ByteArrayInputStream inputStream;

    public ByteArrayServletInputStream(byte[] buffer) {
        this.inputStream = new ByteArrayInputStream(buffer);
    }

    @Override
    public boolean isFinished() {
        return inputStream.available() <= 0;
    }

    @Override
    public boolean isReady() {
        return inputStream.available() > 0;
    }

    @Override
    public void setReadListener(ReadListener listener) {
    }

    @Override
    public int read() throws IOException {
        return inputStream.read();
    }

    @Override
    public int read(byte[] b) throws IOException {
        return inputStream.read(b);
    }

    @Override
    public int read(byte[] b, int off, int len) throws IOException {
        return inputStream.read(b, off, len);
    }
}